import BaseModel from '../BaseModel.js';
import brightness from '@system.brightness';
import LogUtil from '../../common/baseUtil/LogUtil.js';

let logUtil = new LogUtil();

/**
 * brightness service class
 */
export default class SystemBrightnessModel extends BaseModel {
    setValue(value) {
        brightness.setValue({
            value: value
        })
    }
    getValue(success) {
        logUtil.log('Get brightness value is begin');
        try {
            brightness.getValue({
                success,
                fail(data, code) {
                    logUtil.log('Get brightness value is failed, data: ' + data);
                },
                complete() {
                    logUtil.log('Get brightness value is complete');
                }
            })
        } catch (e) {
            logUtil.error('Get brightness value is ' + e);
        }
        logUtil.info('Get brightness value is end');
    }
    getMode (success) {
        logUtil.log('Get mode value is begin');
        try {
            brightness.getMode({
                success,
                fail(data, code) {
                    logUtil.log('Get mode value is failed, data: ' + data);
                },
                complete() {
                    logUtil.log('Get mode value is complete');
                }
            })
        } catch (e) {
            logUtil.error('Get mode value is ' + e);
        }
        logUtil.info('Get mode value is end');
    }
    setMode (mode) {
        logUtil.log('Set mode value is begin');
        try {
            brightness.setMode({
                mode: mode,
                fail(data, code) {
                    logUtil.log('Set mode value is failed, data: ' + data);
                },
                complete() {
                    logUtil.log('Set mode value is complete');
                }
            })
        } catch (e) {
            logUtil.error('Set mode value is ' + e);
        }
        logUtil.info('Set mode value is end');
    }
    setKeepScreenOn (keep, success) {
        logUtil.log('=shijie=setKeepScreenOn value is begin');
        try {
            brightness.setKeepScreenOn({
                keepScreenOn: keep,
                success() {
                    success(keep)
                },
                fail(data, code) {
                    logUtil.log('=shijie=setKeepScreenOn value is failed, data: ' + data);
                },
                complete() {
                    logUtil.log('=shijie=setKeepScreenOn value is complete');
                }
            })
        } catch (e) {
            logUtil.error('=shijie=setKeepScreenOn value is ' + e);
        }
        logUtil.info('=shijie=setKeepScreenOn value is end');
    }
}